package com.kmxd.ams.app.event.summary;

import com.kmxd.ams.app.event.summary.command.BoxSummaryCmd;
import com.kmxd.ams.app.event.summary.command.ProjectSummaryCmd;
import com.kmxd.ams.app.event.summary.command.VolumeSummaryCmd;
import com.kmxd.ams.client.event.summary.SummaryBoxEvent;
import com.kmxd.ams.client.event.summary.SummaryProjectEvent;
import com.kmxd.ams.client.event.summary.SummaryVolumeEvent;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.transaction.event.TransactionalEventListener;

/**
 * 汇总档案监听实现
 *
 * @author nickbi
 */
@Slf4j
@Component
@AllArgsConstructor
public class SummaryArchListener {
  private final VolumeSummaryCmd volumeSummaryCmd;
  private final BoxSummaryCmd boxSummaryCmd;
  private final ProjectSummaryCmd projectSummaryCmd;

  @Async
  @TransactionalEventListener(fallbackExecution = true)
  public void summaryVolume(SummaryVolumeEvent event) throws Exception {
    volumeSummaryCmd.summary(event);
  }

  @Async
  @TransactionalEventListener(fallbackExecution = true)
  public void summaryBox(SummaryBoxEvent event) throws Exception {
    boxSummaryCmd.summary(event);
  }

  @Async
  @TransactionalEventListener(fallbackExecution = true)
  public void summaryProject(SummaryProjectEvent event) throws Exception {
    projectSummaryCmd.summary(event);
  }
}
